﻿﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>预排产齐套性检查</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <link rel="stylesheet" href="/InSiteWebApplication/Content/webuploader/webuploader.css" />
    <style>
        .easyui-linkbutton
        {
            margin-left: 20px;
        }
        table tr td
        {
            padding: 0px 5px;
        }
        #ApsPoolForm
        {
            padding: 10px 0px;
        }
        .priority
        {
            margin: 0 10px;
        }
        .fontRight
        {
            text-align: right;
            padding: 5px 0;
            display: grid;
        }
        .tableDiv div{float:left;padding-top:10px;text-align:right}
        .textLeft{width:35%}
        .textRight{width:65%;padding-right:24px;}
    </style>
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="查询区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <form id="searchForm" method="post">
            <table>
                <tr class="divLabel">
                    <td> 主制分厂</td>
                    <td>
                        <input id="orgfactory" name="orgfactory" class="easyui-combobox" style="width: 150px;height: 22px"  />
                    </td>
                    <td>转工计划状态</td>
                    <td>
                        <input id="status" name="status" class="easyui-combobox" style="width: 150px;height: 22px"  />
                    </td>
                    <td>转工计划开始</td>
                    <td>
                        <input name="shipStarts" class="easyui-datebox" style="width: 150px; height: 22px" id="shipStarts"/>
                        至
                        <input name="shipStarte" class="easyui-datebox" style="width: 150px; height: 22px" id="shipStarte"/>
                    </td>
                    <td> 不齐套过滤</td>
                    <td >
                        <input id="isComp" name="isComp" class="easyui-combobox" style="width: 450px;height: 22px" data-options='editable:false,multiple:true' />
                    </td>
                </tr>
                <tr class="divLabel">
                    <td>主卡批次号</td>
                    <td>
                        <input id="Text15" name="ContainerName" class="easyui-textbox" style="width: 150px; height: 22px" />
                    </td>
                    <td>订单号</td>
                    <td>
                        <input id="Text16" name="MfgOrderName" class="easyui-textbox" style="width: 150px;height: 22px" />
                    </td>
                    <td>转工计划结束</td>
                    <td>
                        <input name="shipEnds" class="easyui-datebox" style="width: 150px; height: 22px" />
                        至
                        <input name="shipEnde" class="easyui-datebox" style="width: 150px; height: 22px" />
                    </td>
                    <td> </td> <!--预排周期-->
                    <td rowspan="2">
                        <!--<input id="ContainerStatus" name="ContainerStatus" class="easyui-combobox" style="width: 150px;height: 22px" />-->
                        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a>
                    </td>
                    <td >
                        
                    </td>
                </tr>
            </table>
            </form>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="生产准备管控" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <table id="ApsProducePreTable" style="height: 400px; width: 100%" data-options="rownumbers:true,toolbar:'#tb'">
            </table>
            <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            group:'paging-tail-btns',
                            id:'pageGo'
                    }]
                    ">
            </div>
            <div id="tb" style="padding: 5px; height: auto">
               <!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()"> 获取预排计划</a> 
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.calcStepDuration()">计算优先级</a> -->
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.apsPrePlan()">预排制造计划</a> 
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.exportData()">预排结果导出</a>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div id="tabs" class="easyui-tabs" data-options="tools:'#tab-tools'">
            <div title="工艺生产准备清单" style="padding: 10px;">
                <table id="WorkflowProTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
            <div title="排产数据异常清单" style="overflow: auto; padding: 10px; display: none;">
                <table id="ApsTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
            <div title="工装工具缺件清单" style="padding: 10px; display: none;">
                <table id="ToolTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
            <div title="工序主辅材缺料清单" style="padding: 10px; display: none;">
                <table id="WsAuxMaterialTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
            <div title="主辅材汇总缺料清单" style="padding: 10px; display: none;">
                <table id="AuxMaterialTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
            <div title="设备状态异常清单" style="padding: 10px; display: none;">
                <table id="ResourceTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
            <div title="特殊过程异常清单" style="padding: 10px; display: none;">
                <table id="SpotcheckTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
            <div title="质量预警" style="padding: 10px; display: none;">
                <table id="QualityTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
            <div title="数控程序" style="padding: 10px; display: none;">
                <table id="NcProgramTable" style="height: 240px" data-options="rownumbers:true">
                </table>
            </div>
        </div>
         <div id="tab-tools" style="padding-right:20px;line-height:27px;">
        <a href="javascript:void(0)" class="easyui-linkbutton"  onclick="page.reviewDetail()">复查</a>
        <a href="javascript:void(0)" class="easyui-linkbutton"  onclick="page.exportDetail()">导出</a>
    </div>
    </div>
    <!--信息提示区域-->
    <div id="statusMessage" style="font-size: 14px; height: 40px">
    </div>
    <div id="dd" style="display: none">
        <form id="EditForm">
        <div  style="margin: 0 5px; display: table; padding-top: 15px">
           <div style="border-bottom:1px solid #ddd;color:#2f97c4">
                任务说明
           </div>
           <div>
           热表厂专用，根据待接收的转工计划，参考计划开始时间和设备班次、日历，进行无限能力正排。</br>
                   <span style="color:red">*注:无限能力排产时，工步计划开始时间参考设备班次、日历进行连续排产，即单工步加工连续执行。</span> 
           </div>
           <div style="border-bottom:1px solid #ddd;color:#2f97c4">
                基础配置
           </div>
           <div class="tableDiv">
                <div class="textLeft">任务名称: <input id="taskName" name="taskName" class="easyui-combobox" style="width: 150px; height: 22px" readonly
                    data-options="
                    data:[{id:'1',text:'预排制造计划（工步）'}],
                    valueField: 'id',
                    textField: 'text',value:'1'" /></div>
                <div class="textRight">分厂: <input id="factory" name="factory" class="easyui-combobox" style="width: 150px; height: 22px"  readonly/></div>
                <div class="textLeft">开始时间: <input id="Text8" name="startTime" class="easyui-datebox" style="width: 150px; height: 22px" /></div>
                <div class="textRight">重复周期(天): <input id="Text9" name="cycle" class="easyui-numberbox" style="width: 150px; height: 22px" /></div>
                <div class="textLeft">结束时间: <input id="Text10" name="endTime" class="easyui-datebox" style="width: 150px; height: 22px" /></div>
                <div class="textRight">任务描述: <input id="Text11" name="taskDes" class="easyui-input" style="width: 150px; height: 22px" /></div>
           </div>
           <div style="border-bottom:1px solid #ddd;color:#2f97c4">
                任务选项
           </div>
           <div class="tableDiv">
                <div class="textLeft">排  产       池: <input id="ApsPool" name="ApsPool" class="easyui-combobox" style="width: 150px; height: 22px" /></div>
                <div class="textRight">连续加工序间隔时间(小时): <input id="specTime" name="apsTime" class="easyui-numberbox" style="width: 150px; height: 22px" /></div>
                <div class="textLeft">预排参考: <input id="Text3" name="apsPre" class="easyui-combobox" style="width: 150px; height: 22px"  
                    data-options="data:[{id:'1',text:'转工计划开始时间'}],
                    valueField: 'id',
                    textField: 'text',value:'1'"/></div>
                <div class="textRight">预排覆盖周期(天) : <input id="Text4" name="apsCycle" class="easyui-numberbox" style="width: 150px; height: 22px" /></div>
                <div style="width:100%;padding-right:24px;">预警规则: <input id="Text5" name="apsRule" class="easyui-tagbox" style="width: 87%; height: 22px" 
                 data-options="data:[{id:'1',text:'预排计划结束超转工计划结束'}],
                    valueField: 'id',
                    textField: 'text',
                    limitToList: true,
                    hasDownArrow: true,
                    prompt: '请选择预排检查'"
                /></div>
                <div style="width:100%;padding-right:24px;">预排检查: <input id="apsCheck" name="apsCheck" class="easyui-tagbox" style="width: 87%; height: 22px" 
                    data-options="data:page.columns,
                    valueField: 'id',
                    textField: 'text',
                    limitToList: true,
                    hasDownArrow: true,
                    prompt: '请选择预排检查'"/></div>
           </div>

           <div style="text-align:center;padding-top:30px;display: flow-root;width:100%;">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.saveStepApsPlan()">确定</a> 
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#dd').dialog('close')">取消</a>
           </div>
        </div>
        </form>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/dayjs.min.js" type="text/javascript"></script>
<script type="text/javascript">
    //创建人：longb
    //日期：2024-07-19
    //描述：预排产计划
    var page = {
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ApsPreProducePreparationHandler.ashx",
        columns:[{ id: 'ISWORKFLOW', text: '工艺路线' }, { id: 'ISAPS', text: '排产数据' }, { id: 'ISTOOL', text: '工装工具' }, { id: 'ISMATERIAL', text: '生产物资' }, { id: 'ISRESOURCE', text: '设备状态' }, { id: 'ISSPOTCHECK', text: '特殊过程'}],
        factoryid:null,
        init: function () {
            page.initPageData2();
            page.initPageData();
            page.initCombobox();
            page.bind();
            NewcustomizedEasyuiPagination('pp'); //定制化分页
        },
        initPageData: function () {
            page.post(getRootPath() + "/Ashx/CommonHandler.ashx", { action: "getFactory" }, true, function (res) {
                $('#orgfactory').combobox({
                    valueField: 'FACTORYID',
                    textField: 'FACTORYNAME',
                    panelHeight: 200,
                    data: res, //下拉数据
                });
                 $('#factory').combobox({
                    valueField: 'FACTORYID',
                    textField: 'FACTORYNAME',
                    panelHeight: 200,
                    data: res, //下拉数据
                });
            });
        },

        initPageData2:function(){
            page.post(null,{ action: "initPageData" }, true, function (res) {
                $('#ApsPool').combobox({
                    valueField: 'APSPOOLID',
                    textField: 'APSPOOLNAME',
                    panelHeight: 200,
                    data: res.DBTable, //下拉数据
                });
                page.factoryid=res.ReturnData;//当前登录人所属分厂
            });

        },

        initCombobox: function () {
            $('#status').combobox({
                data: [{ id: '2', text: '已确认' }, { id: '3', text: '已接收' }, { id: '', text: '全部'}],
                valueField: 'id',
                textField: 'text',
                value: '',
                panelHeight: 100
            });
            $('#isComp').combobox({
                data: page.columns,
                valueField: 'id',
                textField: 'text',
                value: 'ISWORKFLOW,ISAPS,ISTOOL,ISMATERIAL,ISRESOURCE,ISSPOTCHECK',
                panelHeight: 200,
                onSelect: function (row) {
                    var opts = $(this).combobox('options');
                    var el = opts.finder.getEl(this, row[opts.valueField]);
                    el.find('input.combobox-checkbox')._propAttr('checked', true);
                },
                onUnselect: function (row) {
                    var opts = $(this).combobox('options');
                    var el = opts.finder.getEl(this, row[opts.valueField]);
                    el.find('input.combobox-checkbox')._propAttr('checked', false);
                },
                formatter: function (row) {
                    var opts = $(this).combobox('options');
                    return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField] + '</input>';
                },
                onChange:function(newValue, oldValue){
                    if(newValue.length==0||newValue.length==page.columns.length){
                        $.each(page.columns,function(index,item){
                            $('#ApsProducePreTable').datagrid('showColumn',item.id);
                        });
                    }else{

                   page.columns.forEach(function (item) {
                        var isExist = newValue.some(function (i) {
                             return i === item.id
                        });
                        if(!isExist){$('#ApsProducePreTable').datagrid('hideColumn',item.id);}else{
                        $('#ApsProducePreTable').datagrid('showColumn',item.id);
                        }
                        });
                        }
                }
            });
            $('#shipStarts').datebox('setValue', dayjs().format('YYYY-MM-DD'));
            $('#shipStarte').datebox('setValue', dayjs().add(3,'day').format('YYYY-MM-DD'));
        },
        gridTableCellStyler: function (value) {
            if (value == 0) { return 'background-color:rgb(236, 128, 141)'; } else if(value==1){ return 'background-color:rgb(149, 242, 2)'; }else{return '';}
        },
        gridTableCellFormatter: function (value) {
            if (value == 0) { return 'x'; } else if(value==1){ return '√'; }else{return '';}
        },
        //页面事件绑定
        bind: function () {
            $('#ApsProducePreTable').datagrid({
                checkOnSelect: true,
                //selectOnCheck: false,
                //singleSelect: true,
                rownumbers: true,
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    NewcustomizedEasyuiPagination('pp'); //定制化分页
                },
                frozenColumns: [[
                 { field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'ISMARK', title: '异常标识', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(row.ISCOMP) }, styler: function (value, row, index) { return page.gridTableCellStyler(row.ISCOMP) } },
                 //{ field: 'SEQUENCE', title: '顺序号', width: 70, align: 'center' }, //排产顺序号
                 { field: 'DURATION', title: '期量(h)', width: 120, align: 'center' },
                 { field: 'WORKFLOWSTEPNAME', title: '转工工序', width: 120, align: 'center' },
                 { field: 'MFGORDERNAME', title: '订单号', width: 120, align: 'center' },
                 //{ field: 'PRODUCTDESC', title: '零件号', width: 120, align: 'center' },
                 { field: 'CONTAINERNAME', title: '主卡批次号', width: 120, align: 'center' },
                 { field: 'FACTORYNAME', title: '主制分厂', width: 120, align: 'center' },
                ]],
                columns: [[
                 { field: 'STARTTIME', title: '转工计划开始', width: 150, align: 'center' },
                 { field: 'ENDTIME', title: '转工计划结束', width: 150, align: 'center' },
                 //{ field: 'MFGENDDDATE', title: '预排计划结束', width: 120, align: 'center' },
                 { field: 'FULLNAME', title: '转出人', width: 70, align: 'center' },
                 { field: 'ISWORKFLOW', title: '工艺路线', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(value) }, styler: function (value, row, index) { return page.gridTableCellStyler(value) } },
                 { field: 'ISAPS', title: '排产数据', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(value) }, styler: function (value, row, index) { return page.gridTableCellStyler(value) } },
                 { field: 'ISTOOL', title: '工装工具', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(value) }, styler: function (value, row, index) { return page.gridTableCellStyler(value) } },
                 { field: 'ISMATERIAL', title: '生产物资', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(value) }, styler: function (value, row, index) { return page.gridTableCellStyler(value) } },
                 { field: 'ISRESOURCE', title: '设备状态', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(value) }, styler: function (value, row, index) { return page.gridTableCellStyler(value) } },
                 { field: 'ISSPOTCHECK', title: '特殊过程', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(value) }, styler: function (value, row, index) { return page.gridTableCellStyler(value) } },
                 { field: 'ISQUALITY', title: '质量预警', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(value) }, styler: function (value, row, index) { return page.gridTableCellStyler(value) } },
                 { field: 'ISNC', title: '数控程序', width: 70, align: 'center', formatter: function (value, row, index) { return page.gridTableCellFormatter(value) }, styler: function (value, row, index) { return page.gridTableCellStyler(value) } },
                 { field: 'XXX', title: '', width: 30 }
                ]],
                onSelect: function (index, row) {
                    page.getApsProducePrepDetailData();
                },
                onUnselect: function (index, row) {
                    page.getApsProducePrepDetailData();
                }
            });
            $("#WorkflowProTable").datagrid({
                columns: [[
                 //{ field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'FACTORYNAME', title: '主制分厂', width: 120, align: 'center' },
                 { field: 'STARTTIME', title: '转工计划开始', width: 150, align: 'center' },
                 { field: 'PRODUCTNAME', title: '件号', width: 90, align: 'center' },
                 { field: 'WORKFLOWSTEPNAME', title: '转工工序', width: 120, align: 'center' },
                 { field: 'WORKFLOWTYPE', title: '工艺类型', width: 90, align: 'center' },
                 { field: 'WORKFLOWINFO', title: '工艺路线', width: 130, align: 'center' },
                 { field: 'WORKFLOWREVISION', title: '版次', width: 80, align: 'center' }
                 ]]
            });
            $("#ApsTable").datagrid({
                columns: [[
                 //{ field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'FACTORYNAME', title: '主制分厂', width: 120, align: 'center' },
                 { field: 'STARTTIME', title: '转工计划开始', width: 150, align: 'center' },
                 { field: 'PRODUCTNAME', title: '件号', width: 90, align: 'center' },
                 { field: 'WORKFLOWSTEPNAME', title: '转工工序', width: 120, align: 'center' },
                 //{ field: 'WORKFLOWINFO', title: '工艺路线', width: 130, align: 'center' },
                 { field: 'WORKFLOWINFO', title: '工艺路线', width: 120, align: 'center',formatter: function (value, row, index) {
                    var url="/InSiteWebApplication/forms/Custom/ReBiao/RBStepParameterMaintPage.html?type=1,3,4"+
                    '&pname='+row.SONPRODUCTNAME+'&pid='+row.PRODUCTID+'&wname='+row.WORKFLOWNAME+'&wid='+row.WORKFLOWID;//encodeURI(
                    return '<a target="_blank" href='+url+' style=""  >'+value+'</a>';
                 }  },
                 { field: 'ISCOMP', title: '缺设备信息', width: 80, align: 'center' },
                 { field: 'ISCOMP2', title: '缺设备时间', width: 90, align: 'center' }
                 ]]
            });
            $("#ToolTable").datagrid({
                columns: [[
                 //{ field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'FACTORYNAME', title: '主制分厂', width: 120, align: 'center' },
                 { field: 'STARTTIME', title: '转工计划开始', width: 150, align: 'center' },
                 { field: 'PRODUCTNAME', title: '件号', width: 90, align: 'center' },
                 { field: 'WORKFLOWSTEPNAME', title: '转工工序', width: 120, align: 'center' },
                  { field: 'WORKFLOWINFO', title: '工艺路线', width: 120, align: 'center',formatter: function (value, row, index) {
                    var url="/InSiteWebApplication/forms/Custom/ReBiao/RBStepParameterMaintPage.html?type=1,3,4"+
                    '&pname='+row.SONPRODUCTNAME+'&pid='+row.PRODUCTID+'&wname='+row.WORKFLOWNAME+'&wid='+row.WORKFLOWID;//encodeURI(
                    return '<a target="_blank" href='+url+' style=""  >'+value+'</a>';
                 }  },
                 { field: 'TOOLNAME', title: '工装编号', width: 100, align: 'center' },
                 { field: 'DESCRIPTION', title: '工装名称', width: 100, align: 'center' },
                 { field: 'RESOURCETYPENAME', title: '工具类型', width: 90, align: 'center' },
                 { field: 'QTY', title: '需求数量', width: 90, align: 'center' },
                 { field: 'LABSTALL', title: '库存数量', width: 100, align: 'center' }
                 ]]
            });
            $("#WsAuxMaterialTable").datagrid({
                columns: [[
                 //{ field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'FACTORYNAME', title: '主制分厂', width: 120, align: 'center' },
                 { field: 'STARTTIME', title: '转工计划开始', width: 150, align: 'center' },
                 { field: 'PRODUCTNAME', title: '件号', width: 90, align: 'center' },
                 { field: 'WORKFLOWSTEPNAME', title: '转工工序', width: 120, align: 'center' },
                  { field: 'WORKFLOWINFO', title: '工艺路线', width: 120, align: 'center',formatter: function (value, row, index) {
                    var url="/InSiteWebApplication/forms/Custom/ReBiao/RBStepParameterMaintPage.html?type=1,3,4"+
                    '&pname='+row.SONPRODUCTNAME+'&pid='+row.PRODUCTID+'&wname='+row.WORKFLOWNAME+'&wid='+row.WORKFLOWID;//encodeURI(
                    return '<a target="_blank" href='+url+' style=""  >'+value+'</a>';
                 }  },
                 { field: 'AUXMATERIALNAME', title: '物料编号', width: 100, align: 'center' },
                 { field: 'DESCRIPTION', title: '物料名称', width: 100, align: 'center' },
                 { field: 'QTY', title: '需求数量', width: 90, align: 'center' },
                 { field: 'LABSTALL', title: '库存数量', width: 100, align: 'center' }
                 ]]
            });
            $("#AuxMaterialTable").datagrid({
                columns: [[
                 //{ field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'AUXMATERIALNAME', title: '物料编号', width: 100, align: 'center' },
                 { field: 'DESCRIPTION', title: '物料名称', width: 100, align: 'center' },
                 { field: 'QTY', title: '需求数量', width: 90, align: 'center' },
                 { field: 'LABSTALL', title: '库存数量', width: 100, align: 'center' },
                 { field: 'DIFFQTY', title: '差额', width: 100, align: 'center' }
                 ]]
            });
            $("#ResourceTable").datagrid({
                columns: [[
                 //{ field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'FACTORYNAME', title: '主制分厂', width: 120, align: 'center' },
                 { field: 'STARTTIME', title: '转工计划开始', width: 150, align: 'center' },
                 { field: 'PRODUCTNAME', title: '件号', width: 90, align: 'center' },
                 { field: 'WORKFLOWSTEPNAME', title: '转工工序', width: 120, align: 'center' },
                 { field: 'WORKFLOWINFO', title: '工艺路线', width: 120, align: 'center',formatter: function (value, row, index) {
                    var url="/InSiteWebApplication/forms/Custom/ReBiao/RBStepParameterMaintPage.html?type=1,3,4"+
                    '&pname='+row.SONPRODUCTNAME+'&pid='+row.PRODUCTID+'&wname='+row.WORKFLOWNAME+'&wid='+row.WORKFLOWID;//encodeURI(
                    return '<a target="_blank" href='+url+' style=""  >'+value+'</a>';
                 }  },
                 { field: 'RESOURCENAME', title: '设备编号', width: 100, align: 'center' },
                 { field: 'DESCRIPTION', title: '设备名称', width: 100, align: 'center' },
                 { field: 'RESOURCETYPENAME', title: '设备类型', width: 90, align: 'center' },
                 { field: 'ERPSTATUS', title: '设备状态', width: 90, align: 'center' }
                 ]]
            });
            
            $("#SpotcheckTable").datagrid({
                columns: [[
                 //{ field: 'PK', checkbox: true, width: 120, align: 'center' },
                 { field: 'FACTORYNAME', title: '主制分厂', width: 120, align: 'center' },
                 { field: 'STARTTIME', title: '转工计划开始', width: 150, align: 'center' },
                 { field: 'PRODUCTNAME', title: '件号', width: 90, align: 'center' },
                 { field: 'WORKFLOWSTEPNAME', title: '转工工序', width: 120, align: 'center' },
                  { field: 'WORKFLOWINFO', title: '工艺路线', width: 120, align: 'center',formatter: function (value, row, index) {
                    var url="/InSiteWebApplication/forms/Custom/ReBiao/RBStepParameterMaintPage.html?type=1,3,4"+
                    '&pname='+row.SONPRODUCTNAME+'&pid='+row.PRODUCTID+'&wname='+row.WORKFLOWNAME+'&wid='+row.WORKFLOWID;//encodeURI(
                    return '<a target="_blank" href='+url+' style=""  >'+value+'</a>';
                 }  },
                 { field: 'SPECIALCOURSESPECREPORTNO', title: '特殊过程确认编号', width: 120, align: 'center' },
                 { field: 'INDATE', title: '有效期', width: 150, align: 'center' }
                 ]]
            });
            //质量预警
            $("#QualityTable").datagrid({
                columns: [[
                 { field: 'MFGORDERNAME', title: '订单', width: 120, align: 'center' },
                 { field: 'CONTAINERNAME', title: '热表批次', width: 150, align: 'center' },
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 90, align: 'center' },
                 { field: 'REWORKQTY', title: '返修数', width: 120, align: 'center' },
                 { field: 'LOSSQTY', title: '报废数', width: 120, align: 'center' },
                 { field: 'RECTIFYMEASURES', title: '整改措施', width: 150, align: 'center' }
                 ]]
            });
            //数控程序
            $("#NcProgramTable").datagrid({
                columns: [[
                 { field: 'NC_NO', title: '数控程序编号', width: 120, align: 'center' },
                 { field: 'NC_NAME', title: '数控程序名称', width: 150, align: 'center' },
                 { field: 'MATERIAL_MARK', title: '加工材料', width: 90, align: 'center' },
                 { field: 'CONTROL_TYPE', title: '控制系统', width: 120, align: 'center' },
                 { field: 'ISTHREE', title: '是否三轴以上数控铣加工', width: 120, align: 'center' },
                 { field: 'ISTYPICAL', title: '是否关键工序', width: 150, align: 'center' },
                 { field: 'EQPIPORFILENAME', title: '设备编号/工艺附件', width: 150, align: 'center' }
                 ]]
            });

            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    NewcustomizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.getApsProducePrepData();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                 var pageNumber = Number($(this).parents('tr').find('.pagination-num').val());
                page.pageSize = $('#pp').find('.pageSize').val() == "" ? 20 : Number($('#pp').find('.pageSize').val());
                page.pageNumber = pageNumber;
                page.getApsProducePrepData();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.reset(true, true);
                page.pageNumber = 1; page.pagetotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });
        },
        //查询
        searchData: function () {
            clearMessage();
            page.pageNumber = 1;
            page.getApsProducePrepData();
            page.clearApsProducePrepDetailTableData();
        },
        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            page.initCombobox();
            page.clearApsProducePrepDetailTableData();
            clearMessage();
        },
       
        //预排制造计划
        apsPrePlan: function () {
            var rows = $('#ApsProducePreTable').datagrid('getChecked');
            if (rows.length == 0) { displayMessage('请勾选至少一条记录再进行操作', false); return; }
            page.post(null,{ action: "reviewDetailData", data: JSON.stringify(rows)}, true, function (res) {
                if (res.Result) {
                    page.getApsProducePrepData();
                }
                displayMessage(res.Message, res.Result);
            });

        },
        //预排制造计划--保存
        saveStepApsPlan: function () {
            var rows = $('#ApsProducePreTable').datagrid('getChecked');
             var frdata = $('#EditForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            data.apsCheck=$('#apsCheck').tagbox('getValues').join(',')
            console.info(JSON.stringify(data));
            page.post(null,{ action: "saveStepApsPlan", fdata: JSON.stringify(data), rdata: JSON.stringify(rows) }, true, function (res) {
                if (res.Result) {
                    page.getApsProducePrepData();
                }
                $('#dd').dialog('close');
                displayMessage(res.Message, res.Result);
            });
        },
        //查询预排转工信息
        getApsProducePrepData: function () {
            var frdata = $('#searchForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            var param = {
                action: "getApsProducePrepData",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber == 0 ? 1 : page.pageNumber,
                data: JSON.stringify(data)
            };
            page.post(null,param, true, function (res) {
                if (res.Result) {
                    page.pagetotal = res.RowCount;
                    $('#ApsProducePreTable').datagrid('loadData', res.DBTable);
                }
            });
        },
        //查询生产准备--明细信息
        getApsProducePrepDetailData: function () {
            var row = $('#ApsProducePreTable').datagrid('getSelected');
             page.clearApsProducePrepDetailTableData(); 
            if (row == null) {return; }
            page.post(null,{ action: "getApsProducePrepDetailData", data:JSON.stringify([row]) }, true, function (res) {
                if (res.Result) {
                    $('#WorkflowProTable').datagrid('loadData', res.DBDataSet.WorkflowProTable);
                    $('#ApsTable').datagrid('loadData', res.DBDataSet.ApsTable);
                    $('#ToolTable').datagrid('loadData', res.DBDataSet.ToolTable);
                    $('#WsAuxMaterialTable').datagrid('loadData', res.DBDataSet.WsAuxMaterialTable);
                    $('#AuxMaterialTable').datagrid('loadData', res.DBDataSet.AuxMaterialTable);
                    $('#ResourceTable').datagrid('loadData', res.DBDataSet.ResourceTable);
                    $('#SpotcheckTable').datagrid('loadData', res.DBDataSet.SpotcheckTable);
                    $('#QualityTable').datagrid('loadData', res.DBDataSet.QualityTable);//质量预警
                    $('#NcProgramTable').datagrid('loadData', res.DBDataSet.NcProgramTable);//数控程序
                }
            });
        },
        //清空所有明细数据
        clearApsProducePrepDetailTableData: function () {
            $('#WorkflowProTable').datagrid('loadData', []);
            $('#ApsTable').datagrid('loadData', []);
            $('#ToolTable').datagrid('loadData', []);
            $('#WsAuxMaterialTable').datagrid('loadData', []);
            $('#AuxMaterialTable').datagrid('loadData', []);
            $('#ResourceTable').datagrid('loadData', []);
            $('#SpotcheckTable').datagrid('loadData', []);
            $('#QualityTable').datagrid('loadData', []);
            $('#NcProgramTable').datagrid('loadData', []);
        },
        //计算优先级
        calcStepDuration:function(){
            var rows = $('#ApsProducePreTable').datagrid('getChecked');
            if (rows.length == 0) { displayMessage('请勾选至少一条记录再进行操作', false); return; }
            var ids=rows.map(({CONTAINERID})=>CONTAINERID);
             page.post(null,{ action: "calcStepDuration", data:ids.join(',')}, true, function (res) {
                if (res.Result) {
                    page.getApsProducePrepData();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();
        },
        //数据导出
        exportData:function(){
            var frdata = $('#searchForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
           page.excuteExport("exprotData",data);
        },
        //导出明细
        exportDetail:function(){
            var tab = $('#tabs').tabs('getSelected');
            var index = $('#tabs').tabs('getTabIndex',tab);
            var row = $('#ApsProducePreTable').datagrid('getSelected');
            if (row == null) {  return; }
            row.index=index;
            page.excuteExport("exprotDetailData",[row]);
            console.info(index);
             
        },
        //复查
        reviewDetail:function(){
            var tab = $('#tabs').tabs('getSelected');
            var index = $('#tabs').tabs('getTabIndex',tab);
            var row = $('#ApsProducePreTable').datagrid('getSelected');
            if (row == null) {  return; }
            row.index=index;
             page.post(null,{ action: "reviewDetailData", data: JSON.stringify([row])}, true, function (res) {
                if (res.Result) {
                    page.getApsProducePrepData();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //执行导出
        excuteExport:function(action,data){
             $.messager.progress({ text: '', msg: '处理中...' });

            var xhr = new XMLHttpRequest();
            //设置响应类型为blob类型
            xhr.responseType = "blob";
            xhr.open("post", page.ajaxUrl, true); //+ "?action=apsLmCalculateExport&containers=" + JSON.stringify(containers)

            /* post 此种传参无效
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.send(JSON.stringify(postData));
            */
            // post 这种传参有效
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.send("action="+action+"&data=" + JSON.stringify(data));


            xhr.onreadystatechange = function () {
                $.messager.progress('close');
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        if (xhr.getResponseHeader("fileDownload") == "1") {
                            var a = window.document.createElement('a');
                            a.href = window.URL.createObjectURL(new Blob([this.response]));
                            a.download = decodeURI(xhr.getResponseHeader("content-disposition").split('filename=')[1]);
                            document.body.appendChild(a)
                            a.click();
                            document.body.removeChild(a)
                        } else {
                            var reader = new FileReader();
                            reader.readAsText(this.response, 'utf-8');
                            reader.onload = function (e) {
                                if(reader.result==""){return;}
                                var result = JSON.parse(reader.result);
                                displayMessage(result.Message, false);
                            }
                        }

                    }
                }
            };
            return;
        },

        //post数据
        post: function (url,param, async, callback) {
            $.ajax({
                type: "Post",
                url:url==null? page.ajaxUrl:url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
    $(function () {
        page.init();
    });



</script>
